package com.example.wheelguide;

import java.io.Serializable;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ProfileCreateActivity extends Activity implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 2929232933893699917L;
	Button button1;
	Address address;
	Barriere barriere;
	GroundCondition groundCondition;
	WheelchairData wheelchairData;
	String profilename;

	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.profile_create);
		
		
		address= new Address();
		barriere = new Barriere();
		groundCondition = new GroundCondition();
		
		button1 = (Button) findViewById(R.id.button_address_enter);
		button1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				
				
				Intent i = new Intent(v.getContext(), AddressActivity.class);
				Bundle bundle = new Bundle();
				bundle.putSerializable("address", address);
				i.putExtras(bundle);
				startActivityForResult(i,0);
				
			}
		});

		button1 = (Button) findViewById(R.id.Button_Barriere_enter);
		button1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				Intent i = new Intent(v.getContext(), BarriereActivity.class);
				Bundle bundle = new Bundle();
				bundle.putSerializable("barriere", barriere);
				i.putExtras(bundle);
				startActivityForResult(i,0);
				
				
			}
		});
		
		button1 = (Button) findViewById(R.id.Button_Ground_condition_enter);
		
		button1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent i = new Intent(v.getContext(), GroundConditionActivity.class);
				Bundle bundle = new Bundle();
				bundle.putSerializable("groundCondition", groundCondition);
				i.putExtras(bundle);
				startActivityForResult(i,0);
				
			}
		});
		
		button1 = (Button) findViewById(R.id.Button_Wheelchair_data_enter);
		
		button1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent i = new Intent(v.getContext(), WheelchairDataActivity.class);
				Bundle bundle = new Bundle();
				bundle.putSerializable("wheelchairData", wheelchairData);
				i.putExtras(bundle);
				startActivityForResult(i,0);
				
			}
		});
		
		

		
		button1 = (Button) findViewById(R.id.button_save);
		button1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				
				System.out.println(address.getStreet_());
//				EditText et = new EditText(v.getContext());
//				et = (EditText) findViewById(R.id.editText_Profile_name);
//				
//				
//				if(et.getText().length()==0)
//				{
//					AlertDialog alertDialog= new AlertDialog.Builder(v.getContext()).create();
//					alertDialog.setTitle("!!!Angaben fehlen!!!");
//					alertDialog.setMessage("Bitte tragen Sie einen "+ getString(R.string.TextView_Profile_name) + " ein.");
//					alertDialog.setButton(1,"OK", new DialogInterface.OnClickListener() {
//					public void onClick(final DialogInterface dialog, final int which) {
//						dialog.cancel(); 
//					}
//					});
//					alertDialog.show();
//					
//				}
//				
//				RadioGroup rg = new RadioGroup(v.getContext());
//				rg = (RadioGroup) findViewById(R.id.radioGroup_Profile_choose);
//				
//				if(rg.getCheckedRadioButtonId()==R.id.radioButton_Wheelchair)
//				{
//					Wheelchair w= new Wheelchair(et.getText().toString(), address, true);
//					w.setKerbside_(kerbside);
//					w.setStairs_(stairs);
//					w.setPitch_(pitch);
//				
//					
//				}
//				else if(rg.getCheckedRadioButtonId()==R.id.radioButton_ElectricWheelchair)
//				{
//					ElectricWheelchair ew= new ElectricWheelchair(et.getText().toString(), address, true);
//					ew.setPitch_(pitch);
//					
//				}
//				else if(rg.getCheckedRadioButtonId()==R.id.radioButton_Chaperone)
//				{
//					Chaperone c= new Chaperone(et.getText().toString(), address, true);
//					c.setKerbside_(kerbside);
//					c.setStairs_(stairs);
//					c.setPitch_(pitch);
//				}
				
				
				
			}
		});
		
		button1 = (Button) findViewById(R.id.button_abort);
		
		button1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent firstStepIntent= new Intent(v.getContext(),FirstStepActivity.class);
				startActivity(firstStepIntent);
				finish();
				
			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}


	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		System.out.println("Result");	
		if(resultCode == 100)//100 is the result Code from AddressActivity
		{
			System.out.println("Result 100");	
			Bundle b = data.getExtras();
			Address a= (Address) b.getSerializable("return_address");
			address=a;
		}
		else if(resultCode == 101)//101 is the result Code from BarriereActivity
		{
			System.out.println("Result 101");	
			Bundle b = data.getExtras();
			Barriere ba = (Barriere) b.getSerializable("return_barriere");
			barriere = ba;
		}
	}

}
